<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Verify;
class LoginController extends Controller {
    public function indexAction(){
       $this->display();
    }


    public function captchaAction($value='')
    {
    	$config =    array(
    		'imageW'      =>  120,
    		'imageH'      =>  40,
		    'fontSize'    =>    18,    // 验证码字体大小
		    'length'      =>    4,     // 验证码位数
		);
		$Verify =   new Verify($config);
		$Verify->entry();
    }

    public function loginAction()
    {
    	if(IS_POST){

            $email = I('post.mail','');
            $password = md5(I('post.password',''));

            $sql = "select * from user where username='{$email}' and password='{$password}'";
            $res = M()->query($sql);

            if($res){
                $_SESSION['username']=$res[0]['username'];
                $_SESSION['id']=$res[0]['id'];
                $_SESSION['face']=$res[0]['face'];

                $this->success('登录成功',U('admin/index/index'));

            }else{
                $this->error('用户名或者密码不对',U('admin/login/index'));

            }

        }
    }


    public function loginoutAction()
    {
        session_unset();
        session_destroy();
        $this->success('退出成功',U('admin/login/index'));
    }

    
}